package com.dgw.bootorderservice.service.impl;

import com.mall.bean.UserAddress;
import com.mall.service.OrderService;
import com.mall.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


/**
 * 1、将服务提供者注册到注册中心（暴露服务）
 * 		1）、导入dubbo依赖（2.6.2）\操作zookeeper的客户端(curator)
 * 		2）、配置服务提供者
 * 
 * 2、让服务消费者去注册中心订阅服务提供者的服务地址
 */
@Service
public class OrderServiceImpl implements OrderService {

	private UserAddress defaultValue= new UserAddress(1, "北京市", "1", "李老师", "", "Y");

	//@Reference(url = "dubbo://192.168.21.1:20880/com.mall.service.UserService:1.0.0")
	//@Reference(version = "*",loadbalance = "random",mock = "force:return null")
	@Reference
	//@Autowired
	private UserService userService;

	@HystrixCommand(fallbackMethod = "initOrderBackBed")
	@Override
	public List<UserAddress> initOrder(String userId) {
		// TODO Auto-generated method stub
		System.out.println("用户id："+userId);
		//1、查询用户的收货地址
		List<UserAddress> addressList = userService.getUserAddressList(userId);
		for (UserAddress userAddress : addressList) {
			System.out.println(userAddress.getUserAddress());
		}
		return addressList;
	}

	private List<UserAddress> initOrderBackBed(String userId) {
		return Arrays.asList(new UserAddress(1,"测试","测试","测试","测试","测试"));
	}
}
